package object5.library.operation;

import object5.library.Book;
import object5.library.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍");
        //用户来输入,要删除哪本书
        //按照序号删除比较科学,因为有的时候可能同一本书有许多本
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删除的书籍的序号");
        int index = scanner.nextInt();
        if(index < 0||index >= bookList.getSize()){
            System.out.println("序号超出范围!");
            return;
        }else{
            Book lastBook = bookList.getBook(bookList.getSize() - 1);
            bookList.setBook(index,lastBook);
            bookList.setSize(bookList.getSize() - 1);
        }
        System.out.println("删除操作完成!");
    }
}
